// c - available colors for players
var svg, c = ["#ff0000", "#00ff00", "#0000ff", "#00ffff", "#ff00ff", "#ffff00", "#000000"], ne = 2;
var view, game;
function addPlayer() {
	document.getElementById('players').appendChild(new Player(ne, 'Player ' + (ne + 1), PLAYER_TYPE_HUMAN, c[ne % c.length]).inputHTML());
	ne++;
}
function removePlayer(i) {
	document.getElementById('players').removeChild(document.getElementById('player' + i));
}
function restart() {
	nr = parseInt(document.getElementById('input-nr').value);
	nc = parseInt(document.getElementById('input-nc').value);
	p = [];
	var pi = 0;
	for(var i = 0; i < ne; i++) {
		if(!document.getElementById('player' + i))
			continue;
		p[pi] = new Player(pi, document.getElementById('player' + i + 'name').value, document.getElementById('player' + i + 'type').value == 'h' ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER, c[i % c.length]);
		pi++;
	}
	if(game)
		game.end();
	game = new Game(nr, nc, p, view, document.getElementById('scoreboard'));
}
function init() {
	// Find your root SVG element
	view = new View(document.getElementById("mySVG"));
}
function reset() {
	view.reset();
}
function zoomin() {
	view.zoomin();
	game.redraw();
}
function zoomout() {
	view.zoomout();
	game.redraw();
}